# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets, QtSerialPort
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtSerialPort import *

def getCurTime(format=0):
    time = QDateTime.currentDateTime()#获取当前时间

    if format == 1:
        fmt = 'hh:mm:ss.zzz'
    elif format == 2:
        fmt = 'yyyy:MM:dd'
    elif format == 3:
        fmt = 'yyyy-MM-dd hh:mm:ss'
    elif format == 10:
        fmt = 'yyyy:MM:dd-hh:mm:ss.zzz'
    else:
        fmt = 'hh:mm:ss'

    timedisplay = time.toString(fmt)#格式化一下时间

    return timedisplay

def ms2formatStr(time, fmt = 1):
    ms = int(time%1000)
    sec = int(time / 1000)
    minute = int(sec / 60)
    hour = int(minute / 60)

    if fmt == 1:
        out = '{:0>2d}:{:0>2d}:{:0>3d}'.format(minute, sec, ms)
    else:
        out = '{:0>2d}:{:0>2d}:{:0>2d}'.format(hour, minute, sec)

    return out

def str2AutoNum(s):
    if type(eval(s)) == float:
        return float(s)

    return int(s)
